/**
 * 
 */
package com.postek.coyote.postekwifi;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

import com.postek.cdf.CDFPTKAndroid;
import com.postek.coyote.postekwifi.bean.LabelBean;
import com.postek.coyote.postekwifi.bean.QRBean;

import java.util.ArrayList;

/**
 * @author yrwang
 *
 */
public class PrintQRActivity extends AppCompatActivity {
	
	private CDFPTKAndroid cdf = MainActivity.cdf;
	private ArrayList<LabelBean> labelBeans = MainActivity.labelBeans;
	
	private Button btnPrint = null;
	private Button btnCancel = null;
	
	private EditText et_QR1 = null;
	private EditText et_QR2 = null;
	private EditText et_QR3 = null;
	private EditText et_QR4 = null;
	private Spinner sp_QR5 = null;
	private Spinner sp_QR6 = null;
	private Spinner sp_QR7 = null;
	private Spinner sp_QR8 = null;
	private Spinner sp_QR9 = null;
	private EditText et_QRS = null;
	private EditText et_print_number=null;
	private EditText et_print_cpnumber=null;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.print_qr);
		
		btnPrint = (Button) findViewById(R.id.btn_printQR_print);
		btnCancel = (Button) findViewById(R.id.btn_printQR_cancel);
		
		et_QR1 = (EditText) findViewById(R.id.et_print_QR1);
		et_QR2 = (EditText) findViewById(R.id.et_print_QR2);
		et_QR3 = (EditText) findViewById(R.id.et_print_QR3);
		et_QR4 = (EditText) findViewById(R.id.et_print_QR4);
		sp_QR5 = (Spinner) findViewById(R.id.sp_print_QR5);
		sp_QR6 = (Spinner) findViewById(R.id.sp_print_QR6);
		sp_QR7 = (Spinner) findViewById(R.id.sp_print_QR7);
		sp_QR8 = (Spinner) findViewById(R.id.sp_print_QR8);
		sp_QR9 = (Spinner) findViewById(R.id.sp_print_QR9);
		et_QRS = (EditText) findViewById(R.id.et_print_QRS);
		et_print_number= (EditText) findViewById(R.id.et_print_number);
		et_print_cpnumber= (EditText) findViewById(R.id.et_print_cpnumber);


		btnCancel.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});
		
		btnPrint.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				int iQR1 = 0;
				int iQR2 = 0;
				int iQR3 = 0;
				int iQR4 = 0;
				int iQR5 = sp_QR5.getSelectedItemPosition();
				int iQR6 = sp_QR6.getSelectedItemPosition() + 1;
				int iQR7 = sp_QR7.getSelectedItemPosition();
				int iQR8 = sp_QR8.getSelectedItemPosition();
				int iQR9 = sp_QR9.getSelectedItemPosition();
				int number=Integer.parseInt(et_print_number.getText().toString());
				int cpnumber=Integer.parseInt(et_print_cpnumber.getText().toString());

				String iQRS = et_QRS.getText().toString();
				
				if(!("".equals(et_QR1.getText().toString()))){
					iQR1 = Integer.parseInt(et_QR1.getText().toString());
				}
				
				if(!("".equals(et_QR2.getText().toString()))){
					iQR2 = Integer.parseInt(et_QR2.getText().toString());
				}
				
				if(!("".equals(et_QR3.getText().toString()))){
					iQR3 = Integer.parseInt(et_QR3.getText().toString());
				}
				
				if(!("".equals(et_QR4.getText().toString()))){
					iQR4 = Integer.parseInt(et_QR4.getText().toString());
				}
				
				int nReturn = cdf.PTK_DrawBar2D_QR(iQR1, iQR2, iQR3, iQR4, iQR5, iQR6, iQR7, iQR8, iQR9, iQRS);
				
				if (nReturn == 0) {
					QRBean bean = new QRBean(iQR1, iQR2, iQR3, iQR4, iQR5, iQR6, iQR7, iQR8, iQR9, iQRS);
					labelBeans.add(bean);
					Toast.makeText(PrintQRActivity.this,  R.string.setting_success, Toast.LENGTH_SHORT).show();
					cdf.PTK_PrintLabel(number,cpnumber);
				} else {
					Toast.makeText(PrintQRActivity.this,  R.string.setting_fail, Toast.LENGTH_SHORT).show();
				}
			}
		});
	}
	
}
